package com.jsp.app.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;
@Controller
public class AdminLoginController {
    @Autowired
    RestTemplate restTemplate;

    @ResponseBody
    @GetMapping("adminlogin")
    public boolean AdminLogin(String username,String password){
        String url="http://localhost:9106/AdminLogin?username={username}&password={password}";
        Map<String,String> map=new HashMap<>();
        map.put("username",username);
        map.put("password",password);
        ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class, map);
        String s = forEntity.toString();
        System.out.println(s);
        String[] s1 = forEntity.toString().split("<|,|[|]");
        String s2 = s1[2];
        System.out.println(s2);
        if (s2.equals("1")){
            return true;
        }else{
            return false;
        }
    }

    @GetMapping("adminLoginPage")
    public String adminLoginPage(){
        return "admin/loginPage";
    }
}
